*
* Prepare data for program-level analysis (Tables 7, 8, B4)
*
* Inputs:
*	"${data_applications_tidy_`year''}", year = 2009 ... 2014
*
* Outputs:
*	"${data_dir}/data_program_level_analysis.dta"
*

* ------------------------------------------------------------------------------
* TODO: change inout files
use "${data_applications_tidy_2009}", clear
forvalues year = 2010/2014 {
	append using "${data_applications_tidy_`year'}"
}

keep if eligibility == 1 & any_ba_listed == 1 & no_funded_version_at_all == 0
keep if ba_program == 1
* ------------------------------------------------------------------------------


sort id program_id rank
bys id program_id: gen ss = _n
keep if ss == 1
drop ss

bys year: egen priority_score_cutoff_mean = mean(priority_score_cutoff)
bys year: egen priority_score_cutoff_sd = sd(priority_score_cutoff)
gen priority_score_cutoff_std = (priority_score_cutoff - priority_score_cutoff_mean)/priority_score_cutoff_sd
lab var priority_score_cutoff_std "Priority-score cutoff (state-funded, standardized)"
lab var priority_score_cutoff "Priority-score cutoff (state-funded)"


gen ba = szint == 1
lab var ba "Bachelor program"

gen priority_score_cutoff_missing = priority_score_cutoff == .
replace priority_score_cutoff = 0 if priority_score_cutoff_missing == 1
replace priority_score_cutoff_std = 0 if priority_score_cutoff_missing == 1

gen full_time = munkarend == 1
lab var full_time "Full-time program"

gen capital_program = kepztelep == "Budapest"
lab var capital_program "Program location: capital"

gen county_capital = kepztelep == "Békéscsaba" | ///
	kepztelep == "Debrecen" | ///
	kepztelep == "Eger" | ///
	kepztelep == "Esztergom" | ///
	kepztelep == "Győr" | ///
	kepztelep == "Kaposvár" | ///
	kepztelep == "Kecskemét" | ///
	kepztelep == "Miskolc" | ///
	kepztelep == "Nyíregyháza" | ///
	kepztelep == "Pécs" | ///
	kepztelep == "Szeged" | ///
	kepztelep == "Szekszárd" | ///
	kepztelep == "Szolnok" | ///
	kepztelep == "Szombathely" | ///
	kepztelep == "Székesfehérvár" | ///
	kepztelep == "Veszprém" | ///
	kepztelep == "Zalaegerszeg"
lab var county_capital "Program location: county capital"

gen stem_program = Stem
lab var stem_program "STEM study program"

gen field_of_study_1 = field_study == 1
lab var field_of_study_1 "Agriculture"

gen field_of_study_2 = field_study == 2
lab var field_of_study_2 "Humanities"

gen field_of_study_3 = field_study == 3
lab var field_of_study_3 "Business and Economics"

gen field_of_study_5 = field_study == 5
lab var field_of_study_5 "Computer Science"

gen field_of_study_6 = field_study == 6
lab var field_of_study_6 "Law and Administration"

gen field_of_study_7 = field_study == 7
lab var field_of_study_7 "Security"

gen field_of_study_8 = field_study == 8
lab var field_of_study_8 "Engineering"

gen field_of_study_9 = field_study == 9
lab var field_of_study_9 "Arts"

gen field_of_study_10 = field_study == 10
lab var field_of_study_10 "Media"

gen field_of_study_11 = field_study == 11
lab var field_of_study_11 "Healthcare"

gen field_of_study_12 = field_study == 12
lab var field_of_study_12 "Pedagogy"

gen field_of_study_13 = field_study == 13
lab var field_of_study_13 "Sport"

gen field_of_study_14 = field_study == 14
lab var field_of_study_14 "Natural Sciences"

gen field_of_study_15 = field_study == 15
lab var field_of_study_15 "Social Sciences"


keep id rank year applicant_id priority_score_cutoff ///
	dominated_dropping_program dominated_flipping_program ///
	costly_dominated_drop_DA_prog costly_dominated_drop_prog ///
	costly_dominated_flip_DA_prog costly_dominated_flip_prog ///
	ba priority_score_cutoff_missing full_time capital_program ///
	county_capital stem_program field_of_study_1 field_of_study_2 ///
	field_of_study_3 field_of_study_5 field_of_study_6 field_of_study_7 ///
	field_of_study_8 field_of_study_9 field_of_study_10 field_of_study_11 ///
	field_of_study_12 field_of_study_13 field_of_study_14 field_of_study_15 ///
	disadv GPA11_std GPA11_missing priority_score_cutoff_std
	 
gen dominated_choice = dominated_dropping_program == 1 | dominated_flipping_program == 1

save "${data_dir}/data_program_level_analysis.dta", replace
